package com.hui.controller;

import com.hui.entity.Goods;
import com.hui.service.GoodsService;
import com.hui.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/09/17/8:18
 * @Description:
 */
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("getGoods/{id}")
    public Goods getGoods(@PathVariable Integer id) {
        return goodsService.getGoodsById(id);
    }

    @PostMapping("updateGoods")
    public Integer updateGoods(@RequestBody Goods goods) {
        return goodsService.updateGoods(goods);
    }

    @DeleteMapping("deleteById/{id}")
    public Integer deleteById(@PathVariable Integer id) {
        return goodsService.deleteById(id);
    }

    @PostMapping("getGoodsByCondition")
    public Map<String, Object> getGoodsByCondition(@RequestBody GoodsVo goodsVo) {
        return goodsService.getGoodsByCondition(goodsVo);
    }

    @Value("${server.port}")
    private String port;

    @GetMapping("port")
    public String getPort() {
        return port;
    }

}
